package com.qqtech.qquan.pub.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.qqtech.core.common.util.BeanUtil;
import com.qqtech.core.frame.dao.BaseDaoImpl;
import com.qqtech.qquan.pub.model.PubFeedback;
import com.qqtech.qquan.pub.model.PubFeedbackQuery;

@Repository
public class PubFeedbackDaoImpl extends BaseDaoImpl<PubFeedback> implements PubFeedbackDao {
	public static final Logger log = LoggerFactory.getLogger(PubFeedbackDaoImpl.class);

	@Override
	public Double queryScoreAvg(PubFeedbackQuery query) {
		if (query == null) {
			return 0.0;
		}
		return sqlSessionTemplate.selectOne(getSqlName("selectScoreAvg"), BeanUtil.toMap(query));
	}

	@Override
	public int feedbackCount(Integer productId, String hasImg,
			Integer level, Integer score, Integer type, Integer status) {
		PubFeedbackQuery query = new PubFeedbackQuery();
		if(productId != null){
			query.setProductId(productId);
			query.setImg(hasImg);
			query.setLevel(level);
			query.setScore(score);
			query.setType(type);
			query.setStatus(status);
			return sqlSessionTemplate.selectOne(getSqlName("feedbackCount"), BeanUtil.toMap(query));
		}
		return 0;
	}
	
}
